package cn.itsource.autoconfigure;

import cn.itsource.pojo.properties.MinAppProPerties;

import cn.itsource.template.WxTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

//微信的自动配置类
@Configuration(proxyBeanMethods = false)
//读取配置
@EnableConfigurationProperties(MinAppProPerties.class)
@Slf4j
public class WxAutoConfiguretion {
    //定义微信工具bean
    @Bean
    public WxTemplate wxTemplate(MinAppProPerties minAppProPerties,RestTemplate restTemplate) {
        WxTemplate wxTemplate = new WxTemplate(minAppProPerties,restTemplate);
        log.info("微信的工具类被创建");
        return wxTemplate;
    }

    //加条件
    @Bean
    @ConditionalOnMissingBean(RestTemplate.class)
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }


}
